<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="ThemeBucket">
<link rel="shortcut icon" type="../image/png">
<title>工人已出发订单</title>
<link rel="stylesheet"
	href="${ctxPath}/static/js/data-tables/DT_bootstrap.css" />
<link rel="stylesheet" type="text/css"
	href="${ctxPath}/static/js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" />
<link href="${ctxPath}/static/css/style.css" rel="stylesheet">
<link href="${ctxPath}/static/css/style-responsive.css" rel="stylesheet">
<link rel="shortcut icon" type="image/x-icon"
	href="${ctxPath }/static/images/lukebang320.ico" media="screen" />
<link rel="icon" href="${ctxPath }/static/images/lukebang320.ico"
	type="image/x-icon" />
<link rel="bookmark" href="${ctxPath }/static/images/lukebang320.ico"
	type="image/x-icon" />
</head>
<body class="sticky-header"
	onload="indexmenu('${oneMenu}','${twoMenu}');">
	<%@ include file="../index/index.jsp"%>
	<section>
		<div class="main-content" style="overflow-y: auto">
			<!-- 地址栏-->
			<div class="page-heading">
				<h3>鹿客帮下单版</h3>
				<ul class="breadcrumb">
					<li><a>我的订单</a></li>
					<li class="active">安装订单</li>
				</ul>
			</div>
			<!--这里是写一些内容的  -->
			<section class="panel">
				<header class="panel-heading custom-tab turquoise-tab">
					<ul class="nav nav-tabs">
						<li class=""><a onclick="clickOrders(1,'pay')">未付款</a></li>
						<li class=""><a onclick="clickOrders(1,'taking')">等待工人接单</a></li>
						<li class=""><a onclick="clickOrders(1,'order')">工人已接单</a></li>
						<li class="active"><a onclick="clickOrders(1,'move')">工人已出发</a></li>
						<li class=""><a onclick="clickOrders(1,'done')">已完成</a></li>
					</ul>
				</header>
				<div class="panel-body">
					<div class="panel panel-default" style="border-bottom-width: 0px">
						<div class="panel-heading">查询条件</div>
						<form id="queryConditionForm">
							<table
								class="table table-striped table-bordered table-hover table-checkable"
								style="border-width: 0" id="datatable_ajax">
								<thead>
									<tr role="row" class="heading">
										<th align="center" width="5%">订单ID</th>
										<th width="8%">顾客姓名</th>
										<th width="8%">顾客手机号</th>
										<th width="15%">预约时间</th>
										<th width="15%">下单日期</th>
										<th width="5%">操作</th>
									</tr>
									<tr role="row" class="filter">
										<td><input type="text"
											class="form-control form-filter input-sm" name="indentID">
										</td>
										<td><input type="text"
											class="form-control form-filter input-sm" name="cuName"
											placeholder="顾客姓名"></td>
										<td>
											<div style="margin-bottom: 5px">
												<input type="text"
													class="form-control form-filter input-sm margin-bottom-5 clearfix"
													name="cuPhone" placeholder="顾客手机号" />
											</div>
										</td>
										<td>
											<div class="input-group date form_datetime"
												style="margin-bottom: 5px" data-link-field="">
												<input class="form-control" size="16" type="text" value=""
													name="subscribeTimeBegin" placeholder="起始时间" readonly>
												<span class="input-group-addon"><span
													class="glyphicon glyphicon-remove"></span></span> <span
													class="input-group-addon"><span
													class="glyphicon glyphicon-calendar"></span></span>
											</div> <input type="hidden" id="" value="" />
											<div class="input-group date form_datetime"
												style="margin-bottom: 5px">
												<input class="form-control" size="16" type="text" value=""
													name="subscribeTimeEnd" placeholder="结束时间" readonly>
												<span class="input-group-addon"><span
													class="glyphicon glyphicon-remove"></span></span> <span
													class="input-group-addon"><span
													class="glyphicon glyphicon-calendar"></span></span>
											</div> <input type="hidden" value="" />
										</td>
										<td><div class="input-group date form_datetime"
												style="margin-bottom: 5px">
												<input class="form-control" size="16" type="text" value=""
													name="beginTimeBegin" placeholder="起始时间" readonly>
												<span class="input-group-addon"><span
													class="glyphicon glyphicon-remove"></span></span> <span
													class="input-group-addon"><span
													class="glyphicon glyphicon-calendar"></span></span>
											</div> <input type="hidden" id="dtp_input1" value="" />
											<div class="input-group date form_datetime"
												style="margin-bottom: 5px">
												<input class="form-control" size="16" type="text" value=""
													name="beginTimeEnd" placeholder="结束时间" readonly> <span
													class="input-group-addon"><span
													class="glyphicon glyphicon-remove"></span></span> <span
													class="input-group-addon"><span
													class="glyphicon glyphicon-calendar"></span></span>
											</div></td>
										<td>
											<div style="margin-bottom: 5px">
												<button style="width: 70px" id="button_refreshQuery"
													type="button"
													class="btn btn-sm green btn-outline filter-submit margin-bottom">
													<i class="fa fa-search"></i> 查询
												</button>
											</div>
											<button style="width: 70px" type="button"
												onclick="$('#queryConditionForm')[0].reset()"
												class="btn btn-sm red btn-outline filter-cancel">
												<i class="fa fa-times"></i> 重置
											</button>
										</td>
									</tr>
								</thead>
							</table>
						</form>
					</div>
					<div class="tab-content">
						<div id="noPayOrders" class="tab-pane active">
							<table id="tb_installIndent"></table>
						</div>
					</div>
				</div>
			</section>
			<!--内容结束  -->
		</div>
	</section>
	<jsp:include page="merchantInfo.jsp"></jsp:include>
	<jsp:include page="workerDetail.jsp"></jsp:include>
	<!-- 配件信息 -->
	<jsp:include page="assestype.jsp"></jsp:include>
		<!-- 取货信息 -->
	<jsp:include page="pickup.jsp"></jsp:include>
	<jsp:include page="sample.jsp"></jsp:include>
</body>
<!--pickers initialization-->
<script type="text/javascript">
	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {
			$('#tb_installIndent')
					.bootstrapTable(
							{
								url : '${ctxPath}/indent/queryInstallIndentByMerchant', //请求后台的URL（*）
								method : 'post', //请求方式（*）
								toolbar : '#toolbar', //工具按钮用哪个容器
								striped : true, //是否显示行间隔色
								cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
								pagination : true, //是否显示分页（*）
								sortable : false, //是否启用排序
								sortName : 'beginTime',
								sortOrder : "desc", //排序方式
								queryParams : oTableInit.queryParams,//传递参数（*）
								sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）
								pageNumber : 1, //初始化加载第一页，默认第一页
								pageSize : 8, //每页的记录行数（*）
								pageList : [ 8, 25, 50, 100 ],
								search : false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
								strictSearch : false,
								showColumns : false, //是否显示所有的列
								showRefresh : true, //是否显示刷新按钮
								minimumCountColumns : 2, //最少允许的列数
								clickToSelect : false, //是否启用点击选中行
								height : 600, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
								uniqueId : "indentId", //每一行的唯一标识，一般为主键列
								showToggle : true, //是否显示详细视图和列表视图的切换按钮
								cardView : false, //是否显示详细视图
								detailView : false, //是否显示父子表
								contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
								columns : [
										{
											field : 'indentId',
											title : '订单ID',
											width : '3%',
											align : "center"
										},
										{
											field : 'beginTime',
											title : '下单时间',
											width : '11%',
											align : "center"
										},
										{
											field : 'subscribeTime',
											title : '预约时间',
											width : '11%',
											align : "center"
										},
										{
											field : 'relievedBao',
											title : '安心宝',
											width : '5%',
											align : "center",
											formatter : function(value, row,
													index) {
												if (value == 1) {
													return '已买';
												} else {
													return '未买';
												}
											}
										},
										{
											field : 'motorNum',
											title : '配件信息',
											width : '10%',
											align : "center",
											formatter : function(value, row,
													index) {
												if ((value != 0 && value != null)
														|| (row.sizhuagouNum != 0 && row.sizhuagouNum != null)
														|| (row.bigouNum != 0 && row.bigouNum != null)) {
													return "<button class='btn btn-success btn-xs' onclick='javascript:viewInstallPartsModalOpen("
															+ row.indentId
															+ ")'><font color='green'>查看信息</font></button>";
												} else {
													return "<font color='red'>暂无信息</font>";
												}
											}
										},
										{
											field : 'addPrice',
											title : '悬赏费用',
											width : '7%',
											align : "center"
										}, 
										{
											field : 'indentPrice',
											title : '订单价格',
											width : '7%',
											align : "center",
											formatter : function(value, row,
													index) {
												return value;

											}
										},
										{
											field : 'merchantsPrice',
											title : '订单总价',
											width : '7%',
											align : "center",
											formatter : function(value, row,
													index) {
												value = value + row.addPrice;
												return value;

											}
										},
										{
											field : 'remark',
											title : '订单备注',
											width : '20%',
											align : "center"
										},
										/* 	{
											field : 'age',
											title : '工龄',
											width : '8%',
											align : "center"
										},
										{
											field : 'tag',
											title : '操作',
											width : '15%',
											align : "center",
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-success btn-xs' onclick='javascript:viewWorkerDetialModalOpen("
														+ row.workerId
														+ ")'>查看详细</button>&nbsp;&nbsp;&nbsp;"
														+ "<button class='btn btn-success btn-xs' onclick='javascript:verifyWorkerThrough("
														+ row.workerId
														+ ")'>取消订单</button>";
											}
										}, */
										{
											field : 'customerAddress',
											title : '顾客姓名',
											width : '8%',
											align : "center",
											formatter : function(value, row,
													index) {
												return value.name;
											}
										},
										{
											field : 'tag',
											title : '顾客详细信息',
											width : '10%',
											align : "center",
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-success btn-xs' onclick='javascript:viewCustomerDetialModalOpen("
														+ row.indentId
														+ ")'>查看顾客信息</button>";
											}
										},
										{
											field : 'isNeedTakeGoods',
											title : '查看取货信息',
											width : '10%',
											align : "center",
											formatter : function(value, row,
													index) {
												if (value == 0) {
													return "<font color='red'>未选择</font>";
												} else {
													return "<button class='btn btn-success btn-xs' onclick='javascript:viewPickupInfoModalOpen("
															+ row.indentId
															+ ")'>查看取货信息</button>";
												}
											}
										},
										{
											field : 'indentId',
											title : '查询商品信息',
											width : '10%',
											align : "center",
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-success btn-xs' onclick='javascript:viewGoodDetailModalOpen("
														+ value
														+ ")'>查看商品信息</button>";
											}
										},
										{
											field : 'tag2',
											title : '取消订单',
											width : '10%',
											align : "center",
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-success btn-xs'  onclick='javascript:quitIndentModalOpen("+ row.indentId+
												",1,"+row.customerId+")'>取消</button>";
											}
										},]
							});
		};

		//得到查询的参数
		oTableInit.queryParams = function(params) {
			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
				limit : params.limit, //页面大小
				offset : params.offset, //页码
				order : params.order,
				sort : params.sort,
				indentID : $("input[name='indentID']").val(),
				subscribeTimeBegin : $("input[name='subscribeTimeBegin']")
						.val(),
				subscribeTimeEnd : $("input[name='subscribeTimeEnd']").val(),
				beginTimeBegin : $("input[name='beginTimeBegin']").val(),
				beginTimeEnd : $("input[name='beginTimeEnd']").val(),
				cuName : $("input[name='cuName']").val(),
				cuPhone : $("input[name='cuPhone']").val(),
				indentStatus : 5,
			};
			return temp;
		};
		return oTableInit;
	};
	$(function() {
		$("#payIndentModal #txt_addPrice").TouchSpin({
			min : 0,
			max : 100,
			step : 1,
			decimals : 2,
			boostat : 5,
			maxboostedstep : 10,
			postfix : '元'
		});
		//1.初始化Table
		var oTable = new TableInit();
		oTable.Init();
		$('.form_datetime').datetimepicker({
			language : 'zh-CN',
			format : "yyyy-mm-dd hh:ii:ss",
			weekStart : 1,
			todayBtn : 1,
			autoclose : 1,
			todayHighlight : 1,
			startView : 2,
			forceParse : 0,
			showMeridian : 1
		});
		$('.form_date').datetimepicker({
			//language : 'fr',
			weekStart : 1,
			todayBtn : 1,
			autoclose : 1,
			todayHighlight : 1,
			startView : 2,
			minView : 2,
			forceParse : 0
		});
		$('.form_time').datetimepicker({
			//language : 'fr',
			weekStart : 1,
			todayBtn : 1,
			autoclose : 1,
			todayHighlight : 1,
			startView : 1,
			minView : 0,
			maxView : 1,
			forceParse : 0
		});
		$("#button_refreshQuery").click(function() {
			var opt = {
				pageNumber : 1,
				query : {
					offset : 0
				}
			};
			//从新开始计数
			$("#tb_installIndent").bootstrapTable('refresh', opt);
		});
		loadInstallIndentGoodDetailTable();
	});
	//取消订单
	function quitIndentModalOpen(indentId) {
		$("input[name='indentID']").val(indentId);
		//alert(indentId);
		$.ajax({
			url : '${ctxPath }/indent/quitInstallIndent',
			type : 'post',
			dataType : 'JSON',
			data : {
				InstallIndentId : indentId
			},
			success : function(data) {
				if (data.status == 0) {
					console.log(data);
					toastr.success("取消成功！");
				} else {
					console.log(data);
					toastr.error("取消失败！");
				}
			}
		});
	}
	//查看那个订单的那个用户
	function viewCustomerDetialModalOpen(id) {
		var viewRow = $('#tb_installIndent').bootstrapTable('getRowByUniqueId',
				id);
		$("#viewCustomerDetialModal #txt_customerName").val(
				viewRow.customerAddress.name);
		$("#txt_customerPhoneNumber").val(viewRow.customerAddress.phone);
		$("#txt_customerAddress").val(viewRow.customerAddress.customerAddress);
		$("#txt_customerRemark").val(viewRow.remark);
		$('#viewCustomerDetialModal').modal('show');
	}
	function viewInstallPartsModalOpen(id) {
		var viewRow = $('#tb_installIndent').bootstrapTable('getRowByUniqueId',
				id);
		$("#txt_repairPartsMotorNum").val(viewRow.motorNum);
		$("#txt_repairPartsSizhuagouNum").val(viewRow.sizhuagouNum);
		$("#txt_repairPartsBigouNum").val(viewRow.bigouNum);
		$('#viewPartsModal').modal('show');
	}
	function viewPickupInfoModalOpen(id) {
		var viewRow = $('#tb_installIndent').bootstrapTable('getRowByUniqueId',
				id);
		$("#txt_pickupPhone").val(viewRow.takeGoodsTel);
		$("#txt_pickupBaseAddress").val(viewRow.baseAddress);
		$("#txt_pickupDetailAddress").val(viewRow.detailAddress);
		$('#viewPickupInfoModal').modal('show');
	}
	//打开浏览安装订单的商品modal
	function viewGoodDetailModalOpen(indentID) {
		$.post('${ctxPath}/good/queryInstallIndentGood', {
			indentID : indentID
		}, function(data) {
			$('#indentGoodDetailTable').bootstrapTable('load',
					data.installIndentGoods);
			var beginNum = 0;
			$.each(data.collapseNumbers, function(index, valueChild) {
				$('#indentGoodDetailTable').bootstrapTable('mergeCells', {
					index : beginNum,
					field : 'type_script',
					rowspan : valueChild,
				});
				beginNum = beginNum + valueChild;
			})
			$("#viewIndentGoodDetailModal").modal('show');
		});
	}
	function loadInstallIndentGoodDetailTable() {
		$('#indentGoodDetailTable')
				.bootstrapTable(
						{
							toolbar : '#toolbar', // 工具按钮用哪个容器
							height : 500,
							columns : [
								{
									field : 'type_script',
									title : '安装基本信息',
									align : "center",
									width : "10%",
									formatter : function(value, row, index) {
										var curtainTypeStr= ! row.good.curtainTypeStr ? "无" : row.good.curtainTypeStr;
										var basic= "品种  :"+ curtainTypeStr;
										return basic;
									}
								},
								{
									field : 'good',
									title : '安装信息',
									align : "center",
									width : "15%",
									formatter : function(value, row, index) {
										var info;
										var installCase = value.installCase == 1? "<br/>布纱安装位置：相同"  : "";
										var structureStr=! value.structureStr ? "无": value.structureStr ;
										var styleStr=! value.styleStr ? "无": value.styleStr ;
										var goodSpecialTypeStr=! value.goodSpecialTypeStr ? "无": value.goodSpecialTypeStr ;
										if (value.type == 0) {
											 info= "结构："
												+ structureStr
												+ "<br/>款式："
												+ styleStr
												+ "<br/>类型："
												+ goodSpecialTypeStr
												+ installCase;
										} else {
											info= "类型："+ goodSpecialTypeStr;
										}
										return info;
									}
								},
								{
									field : 'type',
									title : '款式信息',
									align : "left",
									width : "23%",
									formatter : function(value, row, index) {
										var kuashi="";
										var accessoriesType=! row.accessoriesType ? "无" : row.accessoriesType;
										var pinstallSite=! row.pinstallSite ? "无" : row.pinstallSite;
										var accStr=! row.acc  ? "无装饰头"  : row.acc;
										var panzhuangfangshi=! row.panzhuangfangshi  ? "无"  : row.panzhuangfangshi;
										// 如果是布尺寸或者纱尺寸
										if (value == 0 || value == 1) {
											  kuashi= "布帘配件："
												+ accessoriesType
												+ "，" + accStr
												+ "<br/>安装方式："
												+ pinstallSite
												+ "<br/>安装配件："
												+ panzhuangfangshi;
										}
										// 如果是帘头
										else if (value == 2) {
											kuashi= "帘头安装情况："
													+pinstallSite
													+ "<br/>帘头配件："
													+accessoriesType;
										}
										// 如果是成品帘
										else {
											kuashi="无";
										}
										return kuashi;
									}
								},
								{
									field : 'type',
									title : '尺寸信息',
									align : "center",
									width : "200px",
									formatter : function(value, row, index) {
										// 如果是布尺寸或者纱尺寸
										var size;
										var width=! row.wide ? "0" : row.wide;
										var high=! row.high ? "0" : row.high;
										var saleNumber=! row.saleNumber ? "0"  : row.saleNumber;
										if (value == 0 || value == 1) {
											size= "宽：" + width
													+ "（米），高：" + high
													+ "（米）" + "<br/>杆长："
													+ saleNumber
													+ "（米）";
										}
										// 如果是帘头
										else if (value == 2) {
											size= "宽：" + width
													+ "（米），配件长度："
													+ saleNumber;
										}
										// 如果是成品帘
										else {
											size= "宽：" + width
													+ "（米），高：" +high
													+ "（米）";
										}
										return size;
									}
								}, {
									field : 'remark',
									title : '备注',
									width : "15%",
									align : "center"
								} ]
						});
	}
</script>
<script type="text/javascript"
	src="${ctxPath}/static/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
	src="${ctxPath}/static/js/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript"
	src="${ctxPath}/static/js/orders/public.js"></script>
<script type="text/javascript"
	src="${ctxPath}/static/js/taskManage/public.js"></script>
<!-- tables插件的引用 -->
<script src="${ctxPath}/static/js/bootstrap-table/bootstrap-table.js"></script>
<link href="${ctxPath}/static/js/bootstrap-table/bootstrap-table.css"
	rel="stylesheet" />
<script
	src="${ctxPath}/static/js/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
</html>
